<?php

class spDebugProfiler
{
	static private $inst = null;
	
	private $list = array();
	
	static public function instance()
	{
		if ( static::$inst==null )
			static::$inst = new spDebugProfiler;
			
		return static::$inst;
	}
	
	public function start( $name )
	{
		$this->list[$name] = array();
		$this->list[$name]["starttime"] = microtime(true);
	}
	
	public function end( $name )
	{
		$this->list[$name]["endtime"] = microtime(true);
	}
	
	public function dump()
	{
		foreach ( $this->list as $k => $v )
		{
			$time = $v["endtime"]-$v["starttime"];		
			echo $k.": ".$time."<br/>";
		}
	}
}

// convienence functions

function spProfileStart( $name )
{
	spDebugProfiler::instance()->start( $name );
}

function spProfileEnd( $name )
{
	spDebugProfiler::instance()->end( $name );
}



?>